<script setup lang="ts">
import useStore from '@/store';
import { storeToRefs } from 'pinia';
import { reactive, ref } from 'vue';
import fileUpload from '@/components/InfoCollectionSup/fileUpload.vue';
const { infoCollect } = useStore();
const { form } = storeToRefs(infoCollect);
const { submitCollection } = infoCollect;
const arr = new Array(6).fill(0).map((item, index) => item + index);
const dialogFormVisible = ref(false);
const uploading = ref();
const formLabelWidth = '140px';
const handleSubmit = () => {
  // dialogFormVisible.value = false;
  if (form.value.infoType === 'other')
    submitCollection();
  else uploading.value.submitUpload();
}
defineExpose({
  dialogFormVisible,
})
</script>

<template>
  <el-dialog v-model="dialogFormVisible" title="信息采集">
    <div style="height: 50vh;">
      <el-scrollbar>
        <el-form :model="form">
          <el-form-item label="信息类型" :label-width="formLabelWidth">
            <el-select v-model="form.infoType" class="m-2" placeholder="Select">
              <el-option :value="`file`" />
              <el-option :value="`other`" />
            </el-select>
          </el-form-item>
          <el-form-item :style="{ display: form.infoType === 'file' ? 'flex' : 'none' }" label="文件上传"
                        :label-width="formLabelWidth">
            <file-upload ref="uploading"></file-upload>
          </el-form-item>
          <el-form-item label="信息级别" :label-width="formLabelWidth">
            <el-select v-model="form.infoClass" class="m-2" placeholder="Select">
              <el-option v-for="(item, index) in arr" :key="index" :value="`${item}`" />
            </el-select>
          </el-form-item>
          <el-form-item label="信息内容" :label-width="formLabelWidth">
            <el-input v-model="form.infoContent" placeholder="信息内容"></el-input>
          </el-form-item>
          <el-form-item label="信息有效期" :label-width="formLabelWidth">
            <el-input v-model="form.infoDeadline" placeholder="格式：yyyy-mm-dd"></el-input>
          </el-form-item>
          <el-form-item label="信息来源" :label-width="formLabelWidth">
            <el-select v-model="form.infoSource" class="m-2" placeholder="Select">
              <el-option :value="`内部`" />
              <el-option :value="`外部`" />
            </el-select>
          </el-form-item>
          <el-form-item label="信息提供者" :label-width="formLabelWidth">
            <el-input v-model="form.infoProvider" placeholder="信息提供者"></el-input>
          </el-form-item>
          <el-form-item label="信息提供时间" :label-width="formLabelWidth">
            <el-input v-model="form.infoProvideTime" placeholder="格式：yyyy-mm-dd"></el-input>
          </el-form-item>
          <el-form-item label="信息收集者" :label-width="formLabelWidth">
            <el-input v-model="form.infoCollector" placeholder="信息收集者"></el-input>
          </el-form-item>
          <el-form-item label="信息收集时间" :label-width="formLabelWidth">
            <el-input v-model="form.infoCollectTime" placeholder="格式：yyyy-mm-dd"></el-input>
          </el-form-item>
        </el-form>
      </el-scrollbar>
    </div>
    <template #footer>
			<span class="dialog-footer">
				<el-button @click="dialogFormVisible = false">取消</el-button>
				<el-button type="primary" @click="handleSubmit">提交</el-button>
			</span>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.el-button--text {
  margin-right: 15px;
}

.el-select {
  width: 300px;
}

.el-input {
  width: 300px;
}

.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>

